package com.yike.user.service.impl;

import com.yike.user.entity.UserBankAccount;
import com.yike.user.mapper.UserBankAccountMapper;
import com.yike.user.service.UserBankAccountService;
import com.yike.user.param.UserBankAccountPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户银行账号信息表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-27
 */
@Slf4j
@Service
public class UserBankAccountServiceImpl extends BaseServiceImpl<UserBankAccountMapper, UserBankAccount> implements UserBankAccountService {

    @Autowired
    private UserBankAccountMapper userBankAccountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveUserBankAccount(UserBankAccount userBankAccount) throws Exception {
        return super.save(userBankAccount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserBankAccount(UserBankAccount userBankAccount) throws Exception {
        return super.updateById(userBankAccount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteUserBankAccount(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<UserBankAccount> getUserBankAccountPageList(UserBankAccountPageParam userBankAccountPageParam) throws Exception {
        Page<UserBankAccount> page = new PageInfo<>(userBankAccountPageParam, OrderItem.desc(getLambdaColumn(UserBankAccount::getCreateTime)));
        LambdaQueryWrapper<UserBankAccount> wrapper = new LambdaQueryWrapper<>();
        IPage<UserBankAccount> iPage = userBankAccountMapper.selectPage(page, wrapper);
        return new Paging<UserBankAccount>(iPage);
    }

}
